package br.pucrio.inf.aaaong.models.form.validation;

import java.util.ArrayList;
import java.util.List;

import br.com.caelum.vraptor.ioc.Component;
import br.pucrio.inf.aaaong.models.form.FormField;
import br.pucrio.inf.aaaong.models.form.errors.FormError;

@Component
public class FormValidator {

	public List<FormError> validateWith(FormField field, Object value) {
		ArrayList<FormError> errors = new ArrayList<FormError>();
		List<FormValidation> validations = field.getValidations();
		for (FormValidation validation : validations) {
			List<FormError> validationErrors = validation.getErrors(value, field.getPrettyName());
			errors.addAll(validationErrors);
		}
		return errors;
	}

}
